public class Test {
    public List<List<Integer>> levelOrderBottom(TreeNode root) {
        List<List<Integer>> curlist = new ArrayList<>();

        if(root == null) {
            return curlist;
        }

        Queue<TreeNode> list = new LinkedList<>();

        list.offer(root);
        while(!list.isEmpty()) {

            int size = list.size();
            ArrayList<Integer> one = new ArrayList<>();

            while(size != 0) {

                TreeNode cur = list.poll();
                one.add(cur.val);

                if(cur.left != null) {
                    list.offer(cur.left);
                }
                if(cur.right != null) {
                    list.offer(cur.right);
                }
                size--;
            }
            curlist.add(one);
        }
        Collections.reverse(curlist);
        return curlist;

    }
}
